import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
//        给定两个数，求这两个数的最大公约数
        Scanner sc = new Scanner(System.in);

        int num1 = sc.nextInt();
        int num2 = sc.nextInt();

        int max = (num1 > num2) ? num1 : num2;
        int min = (num1 < num2) ? num1 : num2;

        while (max % min != 0) {
            int k = max % min;
            max =  min;
            min = k;
        }

        System.out.println(min);
    }
}
